﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Burglar.BuisnessLayer.MailingService;

namespace Burglar.BuisnessLayer
{
    class MessageListener1
    {
        string _name;
        MailingClient _client;
        MessageListener _messageCallback;

        public MessageListener1()
        {
            var MessageCallback = System.Security.Principal.WindowsIdentity.GetCurrent();
            if (MessageCallback != null)
                _name = MessageCallback.Name;

        }
        //on new message income 
        //analyze message
        // if domense gone online then form control and send to form
        // if domense gone offline then send command to remove from form
        // domense event -> update panel / ? not seems to be a right place for it

        public void Init(String machineName)
        {
             _messageCallback = new MessageListener();
            var instance = new InstanceContext(_messageCallback);
            _client = new MailingClient(instance);
        }

   

        public void StartListening()
        {
            _client.Subscribe(_name);
        }

        public void StopListening()
        {
            _client.Unsubscribe();
        }


    }
}
